package com.wzh.pool;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import com.sun.deploy.net.HttpRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.*;

/**
 * @description:
 * @author: WZH
 * @time: 2021/5/24 0:39
 */
public class Demo {

    public void tt() {
        CountDownLatch latch = new CountDownLatch(5);
        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        List<Future<String>> futureTaskList = new ArrayList<Future<String>>(5);
        for (int i = 0; i < 5; i++) {
            futureTaskList.add(threadPool.submit(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    latch.countDown();
                    return "ok...";
                }
            }));
        }
        try {
            latch.await();
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        try {
            for (Future<String> future : futureTaskList) {
                System.out.println(future.get());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
// 最简单的HTTP请求，可以自动通过header等信息判断编码，不区分HTTP和HTTPS
        String result1= HttpUtil.get("https://www.baidu.com");

// 当无法识别页面编码的时候，可以自定义请求页面的编码
//        String result2= HttpUtil.get("https://www.baidu.com", CharsetUtil.CHARSET_UTF_8);

//可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中
        HashMap<String, Object> paramMap = new HashMap<>();

        long time = DateUtil.beginOfMonth(DateUtil.date()).getTime();
        paramMap.put("findTime", time);

        String result3= HttpUtil.get("http://172.25.46.14:9001/tagReport/getMonthReport", paramMap);

        System.out.println(result3);

    }

}
